Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

40 implement a secure key storage functionality for the pop server #176

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Tekum-Emmanuella
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@Christiantyemele Christiantyemele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the existing keystore error enum, and also we have to many errors now it will be better to place the errors in a different file

Ok(())
}

fn decrypt(self, secret: KeyStore) -> Result<Vec<u8>, std::io::Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functions you created are not used, where do you call them ?


Ok(decrypted_key)
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also provide tests for your functions

crates/keystore/src/lib.rs Outdated Show resolved Hide resolved
crates/keystore/Cargo.toml Outdated Show resolved Hide resolved
Comment on lines +1 to +23
use thiserror::Error;

#[derive(Debug, Error)]
pub enum KeystoreError {
#[error("File error: {0}")]
FileError(std::io::Error),
#[error("JwkConversionError")]
JwkConversionError,
#[error("KeyPairGenerationError")]
KeyPairGenerationError,
#[error("non compliant")]
NonCompliant,
#[error("not found")]
NotFound,
#[error("parse error")]
ParseError(serde_json::Error),
#[error("serde error")]
SerdeError(serde_json::Error),
#[error("Encryption error: {0}")]
EncryptionError(chacha20poly1305::Error),
#[error("Decryption error: {0}")]
DecryptionError(chacha20poly1305::Error),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your errors need to be more descriptive:

Suggested change
use thiserror::Error;
#[derive(Debug, Error)]
pub enum KeystoreError {
#[error("File error: {0}")]
FileError(std::io::Error),
#[error("JwkConversionError")]
JwkConversionError,
#[error("KeyPairGenerationError")]
KeyPairGenerationError,
#[error("non compliant")]
NonCompliant,
#[error("not found")]
NotFound,
#[error("parse error")]
ParseError(serde_json::Error),
#[error("serde error")]
SerdeError(serde_json::Error),
#[error("Encryption error: {0}")]
EncryptionError(chacha20poly1305::Error),
#[error("Decryption error: {0}")]
DecryptionError(chacha20poly1305::Error),
}
use thiserror::Error;
#[derive(Debug, Error)]
pub enum KeystoreError {
#[error("File operation failed: {0}")]
FileError(#[from] std::io::Error),
#[error("JWK conversion failed")]
JwkConversionError,
#[error("Key pair generation failed")]
KeyPairGenerationError,
#[error("Non-compliant data")]
NonCompliant,
#[error("Item not found")]
NotFound,
#[error("Failed to parse JSON data: {0}")]
ParseError(#[from] serde_json::Error),
#[error("Serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
#[error("Deserialization error: {0}")]
DeserializationError(#[from] serde_json::Error),
#[error("Encryption failed: {0}")]
EncryptionError(#[from] chacha20poly1305::Error),
#[error("Decryption failed: {0}")]
DecryptionError(#[from] chacha20poly1305::Error),
}

Comment on lines +30 to +33
struct FileSystemKeystore {
key: SecretString, // Store key securely using secrecy crate
nonce: Vec<u8>,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this struct? It is not constructed anywhere.

crates/keystore/src/lib.rs Outdated Show resolved Hide resolved

let encrypted_key = cipher
.encrypt(GenericArray::from_slice(&self.nonce), buffer.as_slice())
.map_err(|err| err).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you map the error when not going to propagate it?

debug!("Encryption successful for keystore file: {}", path);

Ok(())
}
Copy link
Collaborator

@Hermann-Core Hermann-Core Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what you are trying to do here. Your encrypt function is not used anywhere, I suppose that you created it to encrypt the keys before storing them? If that's the purpose, then how are you going to decrypt them later?

crates/keystore/src/lib.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement a secure key storage functionality for the pop-server
3 participants